import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';

// 创建开销
class HttpExpenseService {
  /// 创建
  static Future<Response> createExpense({
    int contactId,
    String number,
    String issuedAt,
    String currencyCode,
    double subtotal,
    double inclusiveTaxAmount,
    double exclusiveTaxAmount,
    double total,
    String paidUsing,
    int paidByEmployeeId,
    int accountId,
    int paymentTypeId,
    List<int> attachmentIds,
    List items,
    String notes,
    String dueDate,
  }) async {
    return BaseConfig.httpBase.postJson('/api/expenses', {
      "contact_id": contactId,
      "number": number,
      "issued_at": issuedAt,
      "currency_code": currencyCode,
      "subtotal": subtotal,
      "inclusive_tax_amount": inclusiveTaxAmount,
      "exclusive_tax_amount": exclusiveTaxAmount,
      "total": total,
      "paid_using": paidUsing,
      "paid_by_employee_id": paidByEmployeeId,
      "account_id": accountId,
      "payment_type_id": paymentTypeId,
      "notes": notes,
      "attachment_ids": attachmentIds,
      "items": items,
      'due_at': dueDate,
    });
  }

  static Future<Response> updateExpense({
    int id,
    int contactId,
    String number,
    String issuedAt,
    String currencyCode,
    double subtotal,
    double inclusiveTaxAmount,
    double exclusiveTaxAmount,
    double total,
    String paidUsing,
    int paidByEmployeeId,
    int accountId,
    int paymentTypeId,
    List<int> attachmentIds,
    List items,
    String notes,
    String dueDate,
  }) async {
    return BaseConfig.httpBase.putJson('/api/expenses/$id', {
      "contact_id": contactId,
      "number": number,
      "issued_at": issuedAt,
      "currency_code": currencyCode,
      "subtotal": subtotal,
      "inclusive_tax_amount": inclusiveTaxAmount,
      "exclusive_tax_amount": exclusiveTaxAmount,
      "total": total,
      "paid_using": paidUsing,
      "paid_by_employee_id": paidByEmployeeId,
      "account_id": accountId,
      "payment_type_id": paymentTypeId,
      "notes": notes,
      "attachment_ids": attachmentIds,
      "items": items,
      'due_at': dueDate,
    });
  }

  static Future<Response> showExpense(
    int id,
  ) async {
    return BaseConfig.httpBase.get('/api/expenses/$id', {});
  }

  static Future<Response> reimburseLaterExpense(
    int id,
  ) async {
    return BaseConfig.httpBase
        .postJson('/api/expenses/$id/reimburse_later', {});
  }

  static Future<Response> withdrawReimburse(int id) async {
    return BaseConfig.httpBase.postJson('/api/expenses/$id/withdraw', {});
  }

  static Future<Response> reimburseNowExpense(
    int id, {
    int reimbursePaymentTypeId,
    int reimburseAccountId,
    String issuedAt,
    String chequeNumber,
    String note,
    List<int> attachment_ids,
  }) async {
    return BaseConfig.httpBase.postJson('/api/expenses/$id/reimburse_now', {
      'payment_type_id': reimbursePaymentTypeId,
      'account_id': reimburseAccountId,
      'issued_at': issuedAt,
      'cheque_number': chequeNumber,
      'notes': note,
      "attachment_ids": attachment_ids,
    });
  }

  static Future<Response> deleteExpense(int id) {
    return BaseConfig.httpBase.deleteJson('/api/expenses/$id', {});
  }

  //拒绝
  static Future<Response> reimburseReject(int id, {String reason}) {
    return BaseConfig.httpBase.postJson(
        '/api/expenses/$id/reimburse_reject', {'rejected_reason': reason});
  }

  //expenses列表
  static Future<Response> expandedList() {
    return BaseConfig.httpBase.get('/api/expenses/', {});
  }

  //expense列表
  static Future<Response> reimbursementsList([String type, int page]) {
    return BaseConfig.httpBase.get('/api/reimbursements', {
      'type': type,
      'page': page,
    });
  }

  //批量通过
  static Future<Response> reimbursementsBatchReimburseLater([List<int> ids]) {
    return BaseConfig.httpBase.postJson('/api/reimbursements/batch_approve', {
      'expense_ids': ids,
    });
  }

  //批量通过
  static Future<Response> reimbursementsBatchReimburseNow(
    List<int> ids, {
    int reimbursePaymentTypeId,
    int reimburseAccountId,
    String issuedAt,
    String chequeNumber,
    String note,
  }) {
    return BaseConfig.httpBase
        .postJson('/api/reimbursements/batch_approve_now', {
      'expense_ids': ids,
      'payment_type_id': reimbursePaymentTypeId,
      'account_id': reimburseAccountId,
      'issued_at': issuedAt,
      'cheque_number': chequeNumber,
      'notes': note,
    });
  }

  static Future<Response> batchExpenseDelete(List<int> expenseIds) {
    return BaseConfig.httpBase.postJson('/api/expenses/batch_delete', {
      'expense_ids': expenseIds,
    });
  }

  //批量拒绝
  static Future<Response> reimbursementsBatchReject([List<int> ids]) {
    return BaseConfig.httpBase.postJson('/api/reimbursements/batch_reject', {
      'expense_ids': ids,
    });
  }

  static Future<Response> addPayment(
    int id, {
    int payment_type_id,
    int account_id,
    String currency_code,
    num total,
    String issued_at,
    String cheque_number,
    List<int> attachment_ids,
  }) {
    return BaseConfig.httpBase.postJson('/api/expenses/$id/pay', {
      "payment_type_id": payment_type_id,
      "account_id": account_id,
      "currency_code": currency_code,
      "total": total,
      "issued_at": issued_at,
      "cheque_number": cheque_number,
      "attachment_ids": attachment_ids,
    });
  }

  static Future<Response> getPaymentList(int id) {
    return BaseConfig.httpBase.get('/api/expenses/$id/payments', {});
  }
}
